package com.hxzy.order.controller;

import com.changgou.util.Result;
import com.changgou.util.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.plaf.nimbus.State;

@RestController
@RequestMapping("/orderItem")
public class OrderItemController {

    private static final String CART = "cart_";

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/add")
    public Result add(String name, Integer skuId, Integer number){
        stringRedisTemplate.boundHashOps(CART+name).put(skuId+"", number+"");
        System.out.println(CART+name);
        System.out.println("完成");
        return new Result(true, StatusCode.OK, "添加成功", null);
    }

    @RequestMapping("/list")
    public Result list(String name, Integer skuId){
        Object info = stringRedisTemplate.boundHashOps(CART+name).get(skuId+"");
        Object obj = stringRedisTemplate.boundHashOps(CART+name).keys();
//        System.out.println(obj.values());
        System.out.println(obj);
        return new Result(true, StatusCode.OK, "查询成功", info);
    }

}
